package com.jusyl.cristo.spider.yl;

import java.io.File;
import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jusyl.cristo.spider.lianjia.mapper.LianJiaErShouFangMapper;
import com.jusyl.cristo.spider.lianjia.model.LianJiaErShouFangModel;

import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.PageModelPipeline;
import us.codecraft.webmagic.pipeline.Pipeline;
import us.codecraft.webmagic.selector.Html;

// @Service("abc")
public class LiuBeiPipeline<T> implements PageModelPipeline<T> {


	public void process(ResultItems resultItems, Task task) {
		// TODO Auto-generated method stub
		System.out.println("get page: " + resultItems.getRequest().getUrl());
		//遍历所有结果，输出到控制台，上面例子中的"author"、"name"、"readme"都是一个key，其结果则是对应的value
		for (Map.Entry<String, Object> entry : resultItems.getAll().entrySet()) {
			if(entry.getKey().equals("page")) {
				Page page = (Page)entry.getValue();
				for(String str : page.getHtml().$("li.clear").all()) {
					try {
						
						//需要保存的信息
						Html html = new Html(str);
						LiuBeiModel model = new LiuBeiModel();
						
						File file = new File("LiuBei.txt");
						

					}catch(Exception e) {
						e.printStackTrace();
					}
				}
				
				
			}
		}
		
	}

	@Override
	public void process(T ResultItems, Task arg1) {
		// TODO Auto-generated method stub
		
	}
}
